home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / update~1.z / update~1 / lib / alloca.s next >
Encoding:
Text File  |  1989-08-24  |  830 b   |  39 lines

  1. #APP
  2.  
  3. #  alloca(size) allocate junk in stack frame
  4. #
  5. #  void *alloca(size_t size)
  6. #    this version for minix checks brksize
  7. #    ++jrb    bammi@dsrgsun.ces.cwru.edu
  8. #
  9.     .text
  10.     .even
  11.     .globl _brksize
  12.     .globl _alloca
  13. slush = 32            | desired slush below brksize
  14. _alloca:
  15.     movel    sp@+,a0        | get return addr
  16.     movel    sp@+,d0        | get size 
  17.  
  18.     addql    #1,d0        | ensure address even
  19.     andb    #0xfe,d0    | lop off extra bits
  20.  
  21.     movel    sp,a1        | save old sp in case we fail
  22.     subl    d0,sp        | increase stack frame size by that much
  23.     movel    sp,d0        | set up to return it
  24.  
  25.     moveq    #slush,d1    | check against brk
  26.      addl    _brksize,d1
  27.     cmpl    d1,d0
  28.     bles    outofstack    | not enough stack
  29.  
  30. retn:    lea    sp@(-4),sp    | new top of stack (caller pops this)
  31.  
  32.     jmp    a0@        | return by jmping via saved addr
  33.  
  34. outofstack:
  35.     movel    a1,sp        | restore saved sp
  36.     moveq    #0,d0        | NULL return val
  37.     bras    retn
  38.